/**
定时器
*/
package main

import (
	"fmt"
	"time"
)

func linkDb(ch chan int) {
	time.Sleep(time.Second * 2)
	ch <- 1
}

func main() {
	//生成定时器 每间隔一秒启动一次
	/*	t:= time.NewTicker(time.Second)
		for v := range t.C{  //
			fmt.Println(v) //2019-05-11 16:08:28.725274 +0800 CST m=+1.012001501
		}*/

	//实现超时控制

	ch := make(chan int, 10)
	go linkDb(ch)

	t2 := time.NewTicker(time.Second * 1)
	select {
	case v := <-ch:
		fmt.Println(v)
	//case time.After(time.Second * 1)
	case ti := <-t2.C:
		fmt.Println(ti)
	}
	//关闭定时器  不安会造成内存泄漏
	t2.Stop()
}
